package com.elitesland.system.repo;

import com.elitesland.system.entity.SysUserDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * <pre>
 * 系统用户账号表JPA+QueryDSL访问封装
 * </pre>
 *
 * @author Mir
 * @date 2020/6/15
 */
@Repository
public interface SysUserRepo extends JpaRepository<SysUserDO, Long>, QuerydslPredicateExecutor<SysUserDO> {
    List<SysUserDO> findAllById(Long id);

    List<SysUserDO> findAllByIdIn(List<Long> ids);

    Optional<SysUserDO> findByMobile(String mobile);

    Optional<SysUserDO> findByEmail(String email);

    Optional<SysUserDO> findByUsername(String username);

    Optional<SysUserDO> findByUsernameContaining(String username);

    List<SysUserDO> findBySourceType(String sourceType);

    List<SysUserDO> findAllByTransFlagAndDeleteFlag(Integer transFlag, Integer deleteFlag);

    List<SysUserDO> findAllByDeleteFlagAndIdIn( Integer deleteFlag, List<Long> ids);

    @org.springframework.transaction.annotation.Transactional
    @Modifying
    @Query(value = "update sys_user f set f.trans_flag=?2 where f.id in ?1", nativeQuery = true)
    Integer updateTransFlag(List<Long> ids, Integer transFlag);

    void deleteAllByIdIn(List<Long> ids);
}
